﻿using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using LightLibrary;

public abstract class LibraryBase {
	// === Public =====================================================================================================
	public abstract ExtensionTypeGroup ExtensionTypeGroup { get; }
	public string LibName { get { return Model.LibName; } }
	public string LibRootPath { get { return Model.LibRootPath; } }
	public string LibPath { get { return Model.LibPath; } }

	public void ImportFolder(string path) { }

	public void AddAssets(List<FileInfo> fileInfosToCopy) {
		if(fileInfosToCopy.Count == 0) {
			return;
		}
		var formCopyFiles = new FormCopyFiles();
		var fileInfosToParse = formCopyFiles.CopyFiles(fileInfosToCopy, LibPath);
		foreach(var fileInfo in fileInfosToParse) {
			Model.Assets.Add(CreateAsset(fileInfo));
		}
	}

	public void RemoveAssets(Asset asset) {
		Model.Assets.Remove(asset);
		if (asset.FileInfo.Exists) {
			asset.FileInfo.Delete();
		}
	}

	public List<Asset> GetAssets() {
		return Model.Assets;
	}

	public void SaveToDiskAsXml() {
		XmlTools.Serialize(Model, LibPath + ".xml");
	}

	public void SetModel(LibraryModel libModel) {
		Model = libModel;
	}

	// === Protected ==================================================================================================
	protected LibraryModel Model { get; set; }

	protected LibraryBase(string name) {
		Model = new LibraryModel();
		Model.LibName = name;
		Model.LibRootPath = System.IO.Directory.GetCurrentDirectory();
		Directory.CreateDirectory(LibPath);
	}

	protected abstract Asset CreateAsset(FileInfo fileInfo);
}